package cn.jbt.api.admin.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@EntityListeners(AuditingEntityListener.class)
@Entity
@Table(name = "sys_dict_info", schema = "jbt")
public class SysDictInfo {

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id", nullable = false)
    private Long id;

    @NotBlank(message = "字典名称不能为空")
    @Column(name = "dict_name", nullable = false, length = 100)
    private String dictName;

    @NotBlank(message = "字典编号不能为空")
    @Column(name = "dict_code", nullable = false, length = 100)
    private String dictCode;

    @NotNull(message = "当前状态不能为空")
    @Min(value = 0, message = "当前状态'值'错误")
    @Max(value = 1, message = "当前状态'值'错误")
    @Column(name = "status", nullable = false)
    private Integer status;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @CreatedDate
    @Column(name = "create_time", nullable = false)
    private Date createTime;

    @Column(name = "create_by", nullable = false, length = 64)
    private String createBy = "";

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @LastModifiedDate
    @Column(name = "update_time", nullable = false)
    private Date updateTime;

    @Column(name = "update_by", nullable = false, length = 64)
    private String updateBy = "";

    @Column(name = "remark", nullable = false)
    private String remark = "";

    public void edit(SysDictInfo sysDict) {
        this.dictName = sysDict.dictName;
        this.dictCode = sysDict.dictCode;
        this.status = sysDict.status;
        this.remark = sysDict.remark;
    }
}
